package com.lcm.oj.tme.one;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Coder-lcm
 * @date 2021/5/14
 */
public class Test {
    private String className = "com.lcm.oj.tme.one.Test";
    private Integer id;
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
//        Object[] objs = new Object[10];
//        Arrays.fill(objs, new Object());
//        for (int i = 0; i < 10; i++) {
//            System.out.println(objs[i]);
//        }
//
//        Object[] clone = objs;
//        Arrays.fill(clone, null);
//        for (int i = 0; i < 10; i++) {
//            System.out.println(objs[i]);
//        }
//
//        ExecutorService executorService = Executors.newFixedThreadPool(10);
//        executorService.execute(()->{
//            System.out.println();
//        });


//        System.out.println(150 & 15);
            Test test = new Test();
        Class clazz = Test.class;
        Class<? extends Test> clazz2 = test.getClass();
        Class<?> clazz3 = Class.forName("com.lcm.oj.tme.one.Test");

        System.out.println(clazz == clazz2 && clazz3 == clazz2);
        Method[] methods = clazz.getDeclaredMethods();
        System.out.println("class methods : ");
        for (Method method : methods) {
            if (method.toString().contains("main")){
                continue;
            }
            System.out.println(method);
            System.out.println(method.getParameterCount());
//            method.invoke(, null);
//            method.invoke(test, method.getParameterCount() == 0 ? null : new Integer(1));
        }

        clazz.getDeclaredMethod("method3", int.class).invoke(test, 12);

        System.out.println("---------------------");
        System.out.println("class fields: ");

        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            System.out.println(field + "--");
        }

        System.out.println("-------------------");
        System.out.println("create instance for class");
        Test t1 = (Test)clazz.newInstance();
        System.out.println(t1); //com.lcm.oj.tme.one.Test@60e53b93

        Constructor[] constructors = clazz.getConstructors();
        for (Constructor constructor : constructors) {
            System.out.println(constructor);
        }

        Test t2 = (Test)clazz.getConstructors()[0].newInstance();
        System.out.println(t2);

    }

    public void method1(){
        System.out.println("Method 1");
    }

    public void method2(){
        System.out.println("Method 2");
    }

    public void method3(int param){
        System.out.println("Method 3:" + param);
    }
}
